#!/usr/bin/perl -w

use Test::More tests => 5;
use File::Temp;

# =============================================================
# Cargamos el modulo
# ==============================================================
use_ok('Bench::Test::Remote');

# =============================================================
# Comprobamos que la creacion del objeto es correcta
# =============================================================
SKIP: {
   my $host = $ENV{BENCH_TEST_REMOTE_HOST}
      or skip('because you must set enviroment var BENCH_TEST_REMOTE_HOST', 4);

   my $tempdir = File::Temp::tempdir( CLEANUP => 1 );

   my $remote = Bench::Test::Remote->new (
      HOST       => $ENV{BENCH_TEST_REMOTE_HOST},
      EXECUTABLE => 'echo',
      WORKDIR    => '.',
      BASEDIR    => $tempdir,
   );

   isa_ok($remote, 'Bench::Test::Remote');

   $remote->connect;

   ok($remote->execute_preamble, 'Executing preamble');

   $remote->save_result('Save this!', 'testname');


   my $tempfile = "$tempdir/testname.base";

   open FH, "< $tempfile"
      or die "An error ocurred when trying to open $tempfile";
   my $output = <FH>;
   close FH
      or die "An error ocurred when trying to close $tempfile";

   is ($output, "Save this!\n", 'Saving result to base file');

   ok($remote->execute_postamble, 'Executing postamble');
}
